package com.xbongbong.saas.domain.dao;

import com.xbongbong.saas.domain.entity.ProductStockUpdateEntity;
import com.xbongbong.saas.domain.entity.ProductWarehouseEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author Jian.Wang
 * @version v1.0
 * @date 2019/1/19 15:37
 * @since v1.0
 */
@Repository
@Mapper
public interface ProductWarehouseDao {
    /**
     * 新增一条产品库存信息
     * @param productWarehouse 新增实体
     * @return id
     */
    Integer insert(ProductWarehouseEntity productWarehouse);
    /**
     *  更新一条产品库存信息
     * @param productWarehouse 新增实体
     * @return id
     */
//    Integer update(ProductWarehouseEntity productWarehouse);
    /**
     * 根据ID删除一条产品库存信息
     * @param key 主键索引
     * @param corpid 公司ID
     * @return id
     */
//    Integer deleteByKey(@Param("key") long key, @Param("corpid") String corpid);

    /**
     * 根据id批量删除产品库存信息
     *
     * @param corpid 公司id
     * @param idIn   id集合
     * @return id
     */
    Integer deleteByIdIn(@Param("corpid") String corpid, @Param("idIn") List<Long> idIn);
    /**
     * 根据产品id批量删除产品库存信息
     *
     * @param corpid 公司id
     * @param productIdIn   产品Id集合
     * @return id
     */
    Integer deleteByProductIdIn(@Param("corpid") String corpid, @Param("productIdIn") List<Long> productIdIn);

    /**
     *  根据ID获取一条产品库存信息
     * @param key 主键索引
     * @param corpid 公司ID
     * @return ProductWarehouseEntity
     */
    ProductWarehouseEntity getByKey(@Param("key") Integer key, @Param("corpid") String corpid);
    /**
     *  根据参数查询符合条件的产品库存实体
     * @param param 参数
     * @return 查询供应商产品信息实体集合
     */
    List<ProductWarehouseEntity> findEntitys(@Param("param") Map<String, Object> param);
    /**
     * 获取符合条件的数据数量
     * @param param 参数
     * @return 符合条件数据数
     */
    Integer getEntitysCount(@Param("param") Map<String, Object> param);

    /**
     * 根据仓库Id获取所有产品信息
     * @param warehouseName 仓库名称
     * @param corpid 公司ID
     * @param warehouseId 仓库ID
     * @return id
     */
    Integer updateWarehouseNameByWarehouseId(@Param("warehouseName") String warehouseName, @Param("corpid") String corpid, @Param("warehouseId") long warehouseId);

    /**
     * 批量插入
     * @param productWarehouseList
     */
    void insertBatch(@Param("list") List<ProductWarehouseEntity> productWarehouseList);

    void updateStockBatch(@Param("list")List<ProductWarehouseEntity> productWarehouseEntityList, @Param("corpid") String corpid);

    List<ProductWarehouseEntity> getIdList(@Param("corpid") String corpid, @Param("productIdIn") List<Long> productIdIn);

    void deleteByIdInJob(@Param("idIn") List<Long> delList);

    List<ProductWarehouseEntity> findEntitysForUpdate(@Param("param") Map<String, Object> map);

    void updateStockDB(@Param("warehouseKeyList") Set<String> warehouseKeyList, @Param("list") Collection<ProductStockUpdateEntity> values, @Param("corpid") String corpid);

    List<String> getExistWarehouseKeyList(@Param("corpid") String corpid, @Param("warehouseKeyList") Set<String> warehouseKeyList);

    void updateBatchNotifyMaybeCost(@Param("list") List<ProductWarehouseEntity> list, @Param("corpid") String corpid);
    List<String> getExistWarehouseKeyList(@Param("corpid") String corpid, @Param("warehouseKeyList") Set<String> warehouseKeyList, @Param("warehouseChecked") Integer warehouseChecked);

    List<ProductWarehouseEntity> getExistProductWarehouseList(@Param("corpid") String corpid, @Param("warehouseKeyList") Set<String> warehouseKeyList, @Param("warehouseChecked") Integer warehouseChecked);

    void unbundleWarehouse(@Param("corpid") String corpid, @Param("list") List<ProductWarehouseEntity> unbundleList);

    void rebundleWarehouse(@Param("corpid") String corpid, @Param("list") List<ProductWarehouseEntity> rebundleList);

    void reSetOriNum(@Param("idIn") List<Long> productWarehouseIdList, @Param("corpid") String corpid);

    void updateStockDBWithOri(@Param("warehouseKeyList") Set<String> warehouseKeyList, @Param("list") Collection<ProductStockUpdateEntity> values, @Param("corpid") String corpid);

    List<String> getCorpidList();

    void updateProductWarehouseById(@Param("list")List<ProductWarehouseEntity> productWarehouseEntityList, @Param("corpid")String corpid);

    List<ProductWarehouseEntity> findProductWarehouse(@Param("list")List<Long> prodcutIdList, @Param("corpid")String corpid);

    List<ProductWarehouseEntity> listByProductIdInWasehouseIn(@Param("corpid")String corpid, @Param("list")List<String> warehouseKey);

    List<ProductWarehouseEntity> getCostIsNullWarehouseKey(@Param("corpid") String corpid, @Param("list") List<Long> productIdList);
}
